#include<iostream>
#include<cassert>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>
#include<signal.h>
using std::cout;
using std::endl;
using std::cerr;
void Childprofree(int signo)
{
    assert(signo==SIGCHLD);
    pid_t id=waitpid(-1,nullptr,0);
    if(id>0)
    {
        cout<<"Waiting success!pid::"<<getpid()<<"child process id::"<<id<<endl;
    }
    
}

int main()
{
    signal(SIGCHLD,Childprofree);
    pid_t id=fork();
    if(id<0)
    {
        cout<<"Perror fork!"<<endl;
        exit(0);
    }
    else if(id==0)
    {
        while(true)
        {
            cout<<"I am child process!my pid::"<<getpid()<<endl;
            sleep(2);
        }
        exit(0);
    }
    while(true)
    {
        cout<<"I am parent process!my pid::"<<getpid()<<endl;
        sleep(2);
    }
    return 0;
}
